export default function(coder: any) {

    coder['operator_add'] = function(block: any) {
        var argument1 = coder.valueToCode(block, 'NUM1', coder.ORDER_ASSIGNMENT) || '0'
        var argument2 = coder.valueToCode(block, 'NUM2', coder.ORDER_ASSIGNMENT) || '0'
        return ['('+argument1 + ' + ' + argument2+')', coder.ORDER_ADDITION]
    }

    coder['operator_subtract'] = function(block: any) {
        var argument1 = coder.valueToCode(block, 'NUM1', coder.ORDER_ASSIGNMENT) || '0'
        var argument2 = coder.valueToCode(block, 'NUM2', coder.ORDER_ASSIGNMENT) || '0'
        return ['('+argument1 + ' - ' + argument2+')', coder.ORDER_ADDITION]
    }

    coder['operator_multiply'] = function(block: any) {
        var argument1 = coder.valueToCode(block, 'NUM1', coder.ORDER_ASSIGNMENT) || '0'
        var argument2 = coder.valueToCode(block, 'NUM2', coder.ORDER_ASSIGNMENT) || '0'
        return ['('+argument1 + ' * ' + argument2+')', coder.ORDER_MULTIPLICATION]
    }

    coder['operator_divide'] = function(block: any) {
        var argument1 = coder.valueToCode(block, 'NUM1', coder.ORDER_ASSIGNMENT) || '0'
        var argument2 = coder.valueToCode(block, 'NUM2', coder.ORDER_ASSIGNMENT) || '0'
        return ['('+argument1 + ' / ' + argument2+')', coder.ORDER_DIVISION]
    }

    coder['operator_round'] = function(block: any) {
        var argument = coder.valueToCode(block, 'NUM', coder.ORDER_ASSIGNMENT) || '0'
        return [ `Math.round(${argument})`, coder.ORDER_FUNCTION_CALL]
    }
    
    coder['operator_random'] = function(block: any) {
        var from = coder.valueToCode(block, 'FROM', coder.ORDER_ASSIGNMENT) || '0'
        var to = coder.valueToCode(block, 'TO', coder.ORDER_ASSIGNMENT) || '0'
        return [`${from}+Math.random()*(${to}-${from})`, coder.ORDER_ASSIGNMENT]
    }
    
    coder['operator_and'] = function(block: any) {
        var operand1 = coder.valueToCode(block, 'OPERAND1', coder.ORDER_ASSIGNMENT) || 'false'
        var operand2 = coder.valueToCode(block, 'OPERAND2', coder.ORDER_ASSIGNMENT) || 'false'
        return [`(${operand1} && ${operand2})`, coder.ORDER_ASSIGNMENT]
    }
    
    coder['operator_or'] = function(block: any) {
        var operand1 = coder.valueToCode(block, 'OPERAND1', coder.ORDER_ASSIGNMENT) || 'false'
        var operand2 = coder.valueToCode(block, 'OPERAND2', coder.ORDER_ASSIGNMENT) || 'false'
        return [`(${operand1} || ${operand2})`, coder.ORDER_ASSIGNMENT]
    }
    
    coder['operator_not'] = function(block: any) {
        var operand1 = coder.valueToCode(block, 'OPERAND1', coder.ORDER_ASSIGNMENT) || 'false'
        return [`!(${operand1})`, coder.ORDER_ASSIGNMENT]
    }


    coder['operator_join'] = function(block: any) {
        var string1 = coder.valueToCode(block, 'STRING1', coder.ORDER_ASSIGNMENT) || '""'
        var string2 = coder.valueToCode(block, 'STRING2', coder.ORDER_ASSIGNMENT) || '""'
        return [`${string1} + ${string2}`, coder.ORDER_ASSIGNMENT]
    }

    coder['operator_letter_of'] = function(block: any) {
        var index = coder.valueToCode(block, 'LETTER', coder.ORDER_ASSIGNMENT) || '0'
        var string = coder.valueToCode(block, 'STRING', coder.ORDER_ASSIGNMENT) || '""'
        return [`${string}.charAt(${index})`, coder.ORDER_ASSIGNMENT]
    }
    
    coder['operator_length'] = function(block: any) {
        var string = coder.valueToCode(block, 'STRING', coder.ORDER_ASSIGNMENT) || '""'
        return [`${string}.length`, coder.ORDER_ASSIGNMENT]
    }

    coder['operator_contains'] = function(block: any) {
        var string1 = coder.valueToCode(block, 'STRING1', coder.ORDER_ASSIGNMENT) || '""'
        var string2 = coder.valueToCode(block, 'STRING2', coder.ORDER_ASSIGNMENT) || '""'
        return [`!!${string1}.match(${string2})`, coder.ORDER_ASSIGNMENT]
    }
    
    coder['operator_mod'] = function(block: any) {
        var num1 = coder.valueToCode(block, 'NUM1', coder.ORDER_ASSIGNMENT) || '0'
        var num2 = coder.valueToCode(block, 'NUM1', coder.ORDER_ASSIGNMENT) || '0'
        return [`${num1}%${num2}`, coder.ORDER_ASSIGNMENT]
    }
    
    coder['operator_mathop'] = function(block: any) {
        var num = coder.valueToCode(block, 'NUM', coder.ORDER_ASSIGNMENT) || '0'
        var funcName = block.getFieldValue('OPERATOR') || 'void'
        console.log(funcName)
        return [`Math.${funcName}(${num})`, coder.ORDER_ASSIGNMENT]
 
        //"OPERATOR"
    }
    
    
}